<?php get_header(); ?>
<div class="category-page">
    <div class="container">
        <?php 
        global $wp_query, $paged;
        $current_term = $wp_query->queried_object;
        $current_term_id = $current_term->term_id;
        $color = get_field('main_color', 'portfolio_category_'.$current_term_id);
        $bg_img = get_field('background_image', 'portfolio_category_'.$current_term_id); 
        $deactive = get_field('deactive', 'portfolio_category_'.$current_term_id); ?>
        
        <div class="category-title portfolio-slider">
            <?php /*<div class="left" style="background: url(<?php echo dynamic_url($bg_img['url']); ?>) no-repeat; background-size: 100% 100%; background-position: left center;">
                <div class="category-name">
                    <h2><?php _e($current_term->name);?></h2>
                </div>
            </div>
            <div class="right" style="background-color: <?php echo $color; ?>;">
            </div>
            <div class="border-line"></div>*/ ?>
            
            <?php
            $categories = get_categories(array( 
                'type'          => 'portfolio',
                'parent'        => 0,
                'orderby'       => 'id',
                'hide_empty'    => 0,
                'taxonomy'      => 'portfolio_category'
            ));
            if(!empty($categories)) :
                foreach($categories as $k => $v) :
                    $thumb_img = get_field('thumbnail_image', 'portfolio_category_'.$v->term_id);
                    $category_link = get_term_link($v, 'portfolio_category');
                    $this_deactive = get_field('deactive', 'portfolio_category_'.$v->term_id); ?>
                    
                    <div class="one-third <?php echo ($v->term_id == $current_term_id) ? "current-item " : "other-item "; echo ($this_deactive == 1) ? "deactive" : ""; ?>">
                        <div>
                            <a <?php echo ($this_deactive != 1 && $v->term_id != $current_term_id) ? 'href="'.dynamic_url($category_link).'"' : ""; ?>>
                                <div class="img">
                                    <img src="<?php echo dynamic_url($thumb_img['url']); ?>" alt="<?php _e($v->name);?>"/>
                                </div>
                                
                                <div class="text">
                                    <h2>
                                        <span><?php _e($v->name);?></span>
                                        <?php if($this_deactive == 1) : ?>
                                            <span class="coming"><?php _e("Coming soon...", THB_THEME_NAME); ?></span>
                                        <?php endif; ?>
                                    </h2>
                                </div>
                            </a>
                        </div>
                    </div>
                    
            <?php endforeach;
            endif; ?>
        </div>
        
        <?php if($deactive != 1) : ?>
            <?php 
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $portfolios = new WP_Query( array(
                'posts_per_page' => 9,
            	'post_type' => 'portfolio',
                'paged' => $paged,
            	'tax_query' => array(
            		array(
            			'taxonomy' => 'portfolio_category',
            			'terms' => $current_term_id
            		)
            	),
                'order' => 'ASC',
                'orderby' => 'menu_order'
            )); 
            if($portfolios->have_posts()) : ?>
                <div class="main-portfolios lightbox">
                    <?php
                    while($portfolios->have_posts()) : 
                        $portfolios->the_post();
                        $image_full = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); 
                        $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'portfolio'); ?>
                        <div class="portfolio-item">
                            <a href="<?php echo dynamic_url($image_full[0]); ?>" rel="lightbox-0" class='fresco' 
                                data-fresco-group='<?php echo $current_term_id;?>' 
                                data-fresco-caption="<?php the_title(); ?>"
                                data-fresco-options="ui: 'inside'" 
                                data-fresco-group-options="ui: 'inside'">
                                <img src="<?php echo dynamic_url($thumb[0]); ?>" alt="<?php the_title(); ?>"/>
                            </a>
                        </div>
                    <?php endwhile; ?>
                </div>
                <div class="pagination">
                    <?php
                    if (function_exists("pagination")) {
                        pagination($portfolios->max_num_pages, '2', $current_term_id);
                    } 
                    ?>
                </div>
            <?php else: ?>
                <h2 class="text-center"><?php _e("Coming soon...");?></h2>
            <?php endif; 
            wp_reset_query(); ?>
            
        <?php else: ?>
            <h2 class="text-center"><?php _e("Coming soon...");?></h2>
        <?php endif; ?>
    </div>
</div>
<?php get_footer(); ?>